package com.mufeng.mflibs.utils.ext.widget

import android.widget.ImageView
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.mufeng.mflibs.R
import com.mufeng.mflibs.utils.GlideApp

var ImageView.imageResource: Int
    get() = throw Exception("Property does not have a getter")
    set(value) {
        setImageResource(value)
    }

fun ImageView.loadImage(path: Any?, errorRes: Int = R.drawable.ic_broken_image){
    GlideApp.with(context)
        .asBitmap()
        .diskCacheStrategy(DiskCacheStrategy.ALL)
        .error(errorRes)
        .load(path)
        .into(this)
}

fun ImageView.loadHeadImage(path: Any?, errorRes: Int = R.drawable.icon_default_avatar){
    GlideApp.with(context)
        .asBitmap()
        .diskCacheStrategy(DiskCacheStrategy.ALL)
        .error(errorRes)
        .load(path)
        .into(this)
}